package com.zbkj.crmeb.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.crmeb.system.dao.SystemCountryDao;
import com.zbkj.crmeb.system.model.SystemCountry;
import com.zbkj.crmeb.system.service.SystemCountryService;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class SystemCountryServiceImpl extends ServiceImpl<SystemCountryDao, SystemCountry> implements SystemCountryService {

    /**
     * 功能描述: 通过国家名获取id
     * @Param: [name]
     * @Return: java.lang.Integer
     * @Author: wangzh
     * @Date: 2022/12/22 16:50
     */
    @Override
    public Integer getIdByName(String name) {
        SystemCountry one = this.getOne(Wrappers.<SystemCountry>lambdaQuery().like(SystemCountry::getCountryName, name).or(i -> i.like(SystemCountry::getCode, name)).last("limit 1"));
        if (Objects.isNull(one)){
            return 0;
        }
        return one.getId();
    }
}
